#include "QROHost.h"
#include "QRONode.h"
#include "QRemoteFunction.h"

QRemoteFunction::QRemoteFunction(QObject *_this):_this(_this)
{

}

QRemoteFunction::~QRemoteFunction()
{

}

void QRemoteFunction::pushProperty(const char *name, QVariant value)
{
    QRemoteObject2::pushProperty(_this,name,value);
}

void QRemoteFunction::pushParent(QObject *parent)
{
    QRemoteObject2::setParent(_this,parent);
}

void QRemoteFunction::registerItem(QObject *item)
{
    auto interface = QRemoteObject2::getNetInterface(_this);
    if(!interface)
    {
        qDebug()<<"注册失败，该本对象未注册到网络中";
        return;
    }
    auto host = dynamic_cast<QROHost*>(interface);
    if(!host)
    {
        qDebug()<<"注册失败，只有服务端能注册";
        return;
    }

    host->registerObject(item);
}

void QRemoteFunction::unregisterThis()
{
    QRemoteObject2::unregister(_this);
}

void QRemoteFunction::deleteThis()
{
    unregisterThis();
    delete this;
}

void QRemoteFunction::deleteThisLater()
{
    unregisterThis();
    _this->deleteLater();
}

void QRemoteFunction::onOnline()
{

}

void QRemoteFunction::onOffline()
{

}

bool QRemoteFunction::isSource()
{
    return QRemoteObject2::isSource(_this);
}

bool QRemoteFunction::isReplica()
{
    return QRemoteObject2::isReplica(_this);
}

bool QRemoteFunction::isOccupied()
{
    return QRemoteObject2::occupiedObject(_this) == _this;
}

void QRemoteFunction::occupy()
{
    QRemoteObject2::occupyObject(_this);
}

void QRemoteFunction::release()
{
    QRemoteObject2::releaseObject(_this);
}

QObject *QRemoteFunction::occupiedObject()
{
    return QRemoteObject2::occupiedObject(_this);
}

void QRemoteFunction::onOccupied()
{

}

void QRemoteFunction::onReleased()
{

}
